package com.water.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.water.entity.BeHistory;
import com.water.entity.BeOrder;
import com.water.entity.BeOrderuser;
import com.water.entity.UsUser;
import com.water.service.BeHistoryService;
import com.water.service.BeOrderService;
import com.water.service.BeOrderuserService;
import com.water.service.UsUserService;
import com.water.utils.RandNum;
import com.water.utils.Util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.util.Map;

import static org.springframework.util.ObjectUtils.isEmpty;

/**
 * (BeOrder)表控制层
 *
 * @author makejava
 * @since 2020-12-14 19:18:46
 */
@Controller
@RequestMapping("beOrder")
public class BeOrderController {
    /**
     * 服务对象
     */
    @Resource
    private BeOrderService beOrderService;



    @Resource
    private UsUserService usUserService;
    @Resource
    private BeHistoryService beHistoryService;
    @Autowired
    private Util orderNo;
    @Resource
    private BeOrderuserService beOrderuserService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public BeOrder selectOne(String id) {
        return this.beOrderService.queryById(id);
    }


    @RequestMapping(value = "kai",method = RequestMethod.POST)
    @ResponseBody
    public String insertBeorder(@RequestBody BeOrder beOrder){
        System.out.println(beOrder.toString());
        System.out.println("=================================================");
        System.out.println(beOrder.toString());
        beOrder.setOrderno(RandNum.getGUID());
        BeOrder beOrder1=this.beOrderService.insert(beOrder);
        if(!isEmpty(beOrder1)){
            System.out.println("添加成功");
            return "success";
        }
        return "fail";
    }


    /**
     * 用户申请
     */
    @ResponseBody
    @RequestMapping("addnewClient")
    public BeOrder addNewClient(BeOrder beOrder, BeHistory beHistory,@RequestParam("list") String list){
        System.out.println(list+"LLLLLLLLLLLLL9");
        switch (beOrder.getOrdertype()){
            case 1:
                beOrder.setOrdertype(1);
                break;
            case 2:
                beOrder.setOrdertype(2);
                break;
            case 3:
                beOrder.setOrdertype(3);
                break;
            case 4:
                beOrder.setOrdertype(4);
                break;
            case 5:
                beOrder.setOrdertype(5);
                break;
            case 6:
                beOrder.setOrdertype(6);
                break;
            case 7:
                beOrder.setOrdertype(7);
                break;
            case 8:
                beOrder.setOrdertype(8);
                break;
        }
        if (beOrder.getOrderno() != null) {
            Integer setpid = orderNo.Setpid(1, beOrder.getOrdertype());
            beOrder.setStepid(setpid);
            beOrder.setLasteditdate(orderNo.CreateDate());
            beOrder=this.beOrderService.update(beOrder);
        }else {
            //流程步骤
            Integer setpid = orderNo.Setpid(1, beOrder.getOrdertype());
            beOrder.setStepid(setpid);
            //生成工单号
            Integer ordertype = beOrder.getOrdertype();
            String orderCode = orderNo.getOrderCode(ordertype);
            beOrder.setOrderno(orderCode);
            //创建日期
            beOrder.setCreatedate(orderNo.CreateDate());
            //最后修改日期
            beOrder.setLasteditdate(orderNo.CreateDate());
            //银行
            beOrder.setPaytype("");
            beOrder.setBanknum("");
            beOrder.setBankcompany("");
            //当办理新用户时把原用户信息设为空
            if (beOrder.getOrdertype() == 1) {
                beOrder.setOlduserno("");
                beOrder.setOldusername("");
                beOrder.setOlduserphone("");
                beOrder.setOlduseraddr("");
                beOrder.setOldmeter("");
            }
            System.out.println(beOrder.getOrderno()+"1234567890");
            //订单详细
            JSONArray json = JSONArray.fromObject(list); // 首先把字符串转成 JSONArray  对象
            List<BeOrderuser> orderusers = new ArrayList();
            if(json.size()>0){
                for(int i=0;i<json.size();i++){
                    JSONObject job = json.getJSONObject(i);  // 遍历 jsonarray 数组，把每一个对象转成 json 对象
                    BeOrderuser beOrderuser = new BeOrderuser();
                    beOrderuser.setUsername(job.getString("username"));
                    beOrderuser.setAddress(job.getString("address"));
                    beOrderuser.setSmsphone(job.getString("smsphone"));
                    beOrderuser.setPhone(job.getString("phone"));
                    beOrderuser.setOrderno(beOrder.getOrderno());
                    orderusers.add(beOrderuser);
                }
            }
            //存入历史记录
            beHistory.setOrderno(beOrder.getOrderno());
            beHistory.setStepid(beOrder.getStepid()-1);
            beHistory.setDatee(beOrder.getLasteditdate());
            beHistory.setEmpid(beOrder.getCreateemp());
            System.out.println(beOrder+"ssdsdsss");
            beOrder = beOrderService.insert(beOrder);
            this.beOrderuserService.insertBatch(orderusers);
            this.beHistoryService.insert(beHistory);
            //当办理过户时把原用户禁用（可能会修改）
            if (beOrder.getOrdertype() == 3) {
                //把原用户禁用
                UsUser usUser = usUserService.queryById(beOrder.getOlduserno());//查询对象所有数据
                Object disabled=usUser.getDisabled();//得到禁用启用状态（0启用，1禁用）
                if (disabled.equals(0)) {//if状态为0就修改为1
                    usUser.setDisabled(1);//set状态为1
                    UsUser update = usUserService.update(usUser);//调用修改方法修改状态
                }
            }
        }
        return beOrder;
    }
    /**
     * 过户办理
     */
//    @ResponseBody
//    @PostMapping("addguohu")
//    public BeOrder addguohu(BeOrder beOrder){
//        if (beOrder != null&&beOrder.getOrdertype() == 3) {
//            Integer setpid = orderNo.Setpid(1, beOrder.getOrdertype());
//            beOrder.setStepid(setpid);
//            Integer ordertype = beOrder.getOrdertype();
//            String orderCode = orderNo.getOrderCode(ordertype);
//            beOrder.setOrderno(orderCode);
//            beOrder.setCreatedate(orderNo.CreateDate());
//            beOrder.setLasteditdate(orderNo.CreateDate());
//            beOrder.setPaytype("");
//            beOrder.setBanknum("");
//            beOrder.setBankcompany("");
////            beOrder.setOlduserno("");
////            beOrder.setOldusername("");
////            beOrder.setOlduserphone("");
////            beOrder.setOlduseraddr("");
////            beOrder.setOldmeter("");
//            //把原用户禁用
//            UsUser usUser = usUserService.queryById(beOrder.getOlduserno());//查询对象所有数据
//            Object disabled=usUser.getDisabled();//得到禁用启用状态（0启用，1禁用）
//            if (disabled.equals(0)) {//if状态为0就修改为1
//                usUser.setDisabled(1);//set状态为1
//                UsUser update = usUserService.update(usUser);//调用修改方法修改状态
//            }
//        }
//        return  beOrderService.insert(beOrder);
//    }

    /**
     * 用户申请
     */
//    @ResponseBody
//    @PostMapping("addlookuser")
//    public BeOrder addlookuser(BeOrder beOrder,BeHistory beHistory){
//        if (beOrder.getOrderno() != null) {
//            Integer setpid = orderNo.Setpid(1, beOrder.getOrdertype());
//            beOrder.setStepid(setpid);
//            beOrder.setLasteditdate(orderNo.CreateDate());
//            beOrder=this.beOrderService.update(beOrder);
//        }
//        switch (beOrder.getOrdertype()){
//            case 2:
//                beOrder.setOrdertype(2);
//            break;
//            case 4:
//                beOrder.setOrdertype(4);
//            break;
//            case 5:
//                beOrder.setOrdertype(5);
//            break;
//            case 6:
//                beOrder.setOrdertype(6);
//                break;
//            case 7:
//                beOrder.setOrdertype(7);
//            break;
//            case 8:
//                beOrder.setOrdertype(8);
//            break;
//        }
//        Integer setpid = orderNo.Setpid(1, beOrder.getOrdertype());
//        beOrder.setStepid(setpid);
//            //获得工单号
////        Integer ordertype = beOrder.getOrdertype();
////        String orderCode = orderNo.getOrderCode(ordertype);
////        beOrder.setOrderno(orderCode);
//        Integer ordertype = beOrder.getOrdertype();
//        String orderCode = orderNo.getOrderCode(ordertype);
//        beOrder.setOrderno(orderCode);
//        beOrder.setCreatedate(orderNo.CreateDate());
//        beOrder.setLasteditdate(orderNo.CreateDate());
//        beOrder.setPaytype("");
//        beOrder.setBanknum("");
//        beOrder.setBankcompany("");
////        beOrder.setOlduserno("");
////        beOrder.setOldusername("");
////        beOrder.setOlduserphone("");
////        beOrder.setOlduseraddr("");
////        beOrder.setOldmeter("");
//
//        return  beOrderService.insert(beOrder);
//    }



    /**
     * 跳转到工单管理
     * @return
     */
    @RequestMapping("/be_order")
    public String listorder(Model model, BeOrder beOrder){
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be_order";
    }
    /**
     * 跳转到终止工单
     */
    @RequestMapping("/be_abort")
    public String toabort(){
        return "be/be_abort";
    }

    /**
     *终止工单
     *
     */
    @ResponseBody
    @RequestMapping("/abort")
    public BeOrder beabort(@RequestParam("orderno") String orderno){
        BeOrder beOrderOne = this.beOrderService.queryById(orderno);
        return beOrderOne;
    }
    /**
     * 工单终止原因
     */
    @ResponseBody
    @RequestMapping("/stop")
    public BeOrder stoppabort(BeOrder order){
        BeOrder od=this.beOrderService.update(order);
        return od;
    }

    /**
     * 跳转到初步审核
     * @return
     */
    @RequestMapping("be__audit")
    public String listaudit(Model model, BeOrder beOrder){
        System.out.println("00000000");
        beOrder.setStepid(2);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__audit";
    }

    /**
     * 跳转到等待用户申请的工单
     * @return
     */
    @RequestMapping("be__requestorder")
    public String be__reorder(Model model, BeOrder beOrder){
        beOrder.setStepid(1);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
//        for (Map<String, Object> objectMap : stringObjectMap) {
//            if (objectMap.get("AuditMessage")==null) {
//                stringObjectMap.remove(objectMap);
//            }
//        }
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__requestOrder";
    }
    /**
     * 跳转到交施工费
     * @return
     */
    @RequestMapping("be__pay")
    public String pay(Model model, BeOrder beOrder){
        beOrder.setStepid(3);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__pay";
    }
    /**
     * 跳转到水费清算
     * @return
     */
    @RequestMapping("be__billclear")
    public String billclear(Model model, BeOrder beOrder){
        beOrder.setStepid(4);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__billclear";
    }

    /**
     * 跳转到供水协议
     * @return
     */
    @RequestMapping("be__contract")
    public String cont(Model model, BeOrder beOrder){
        beOrder.setStepid(5);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__contract";
    }

    /**
     * 跳转到施工竣工
     * @return
     */
    @RequestMapping("be__working")
    public String shi(Model model, BeOrder beOrder){
        beOrder.setStepid(6);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__working";
    }

    /**
     * 跳转到通水停水
     * @return
     */
    @RequestMapping("be__open")
    public String tong(Model model, BeOrder beOrder){
        beOrder.setStepid(7);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__open";
    }

    /**
     * 跳转到档案存档
     * @return
     */
    @RequestMapping("be__save")
    public String dangan(Model model, BeOrder beOrder){
        beOrder.setStepid(8);
        Page page = PageHelper.startPage(1,7);
        List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages",page.getPages());//总页数
        map.put("pagenum",page.getPageNum());//Limit起始位
        model.addAttribute("list",stringObjectMap);
        model.addAttribute("page",map);
        return "be/be__save";
    }
    /**
     * 分页
     * @return
     */
    @RequestMapping("/start")
    public String pageorder(Model model, BeOrder beOrder,@RequestParam("stat") int stat,@RequestParam("type") String type){
        if(type.equals("reqoreder")){
            beOrder.setStepid(1);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__requestOrder";
        }
        if(type.equals("audit")){
            beOrder.setStepid(2);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__audit";
        }
        if(type.equals("order")){
            return "be/be_order";
        }
        if(type.equals("pays")){
            beOrder.setStepid(3);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__pay";
        }
        if(type.equals("bil")){
            beOrder.setStepid(4);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__billclear";
        }
        if(type.equals("cont")){
            beOrder.setStepid(5);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__contract";
        }
        if(type.equals("sg")){
            beOrder.setStepid(6);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__working";
        }
        if(type.equals("op")){
            beOrder.setStepid(7);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__open";
        }
        if(type.equals("sa")){
            beOrder.setStepid(8);
            Page page = PageHelper.startPage(stat, 7);
            List<Map<String, Object>> stringObjectMap = this.beOrderService.queryOrder(beOrder);
            Map<String, Object> map = new HashMap<>();
            map.put("totalPages", page.getPages());//总条数
            map.put("pages",page.getPages());//总页数
            map.put("pagenum",page.getPageNum());//Limit起始位
            model.addAttribute("list",stringObjectMap);
            model.addAttribute("page",map);
            return "be/be__save";
        }

        return "error";
    }



    /**
     * 根据类型跳转
     * @param type
     * @return
     */
    @RequestMapping("/jump")
    public String pageorder(@RequestParam("stu") int type,@RequestParam("ordno") String ordno,Model model){
        if(type==1){
            model.addAttribute("ordno",ordno);
            return "be/be__request1";
        }
        if(type==2){
            return "be/be__request3";
        }
        if(type==3){
            return "be/be__request2";
        }
        if(type==4){
            return "be/be__request4";
        }
        if(type==5){
            return "be/be__request5";
        }
        if(type==6){
            return "be/be__request6";
        }
        if(type==7){
            return "be/be__request7";
        }

        return "error";
    }

    /**
     * 处理：初步审核
     * @param model
     * @param ono
     * @return
     */
    @RequestMapping("/shenhe")
    public String pit(Model model,@RequestParam("ono") String ono){
        BeOrder beOrder = beOrderService.queryById(ono);
        model.addAttribute("beOrder",beOrder);
        return "be/be__auditForm";
    }

    /**
     * 处理：交施工费
     * @param model
     * @param ono
     * @return
     */
    @RequestMapping("/shigong")
    public String gong(Model model,@RequestParam("ono") String ono){
        BeOrder beOrder = beOrderService.queryById(ono);
        BeOrderuser beOrderuser = new BeOrderuser();
        beOrderuser.setOrderno(ono);
        System.out.println(beOrderuser+"ppp");
        List<BeOrderuser> orderusers = this.beOrderuserService.queryAll(beOrderuser);
        model.addAttribute("beOrder",beOrder);
        model.addAttribute("orderusers",orderusers);
        return "be/be__payForm";

    }

    /**
     * 处理：水费清算
     * @param model
     * @param ono
     * @return
     */
    @RequestMapping("/qinsuan")
    public String qin(Model model,@RequestParam("ono") String ono){
        BeOrder beOrder = beOrderService.queryById(ono);
        System.out.println(beOrder);
        model.addAttribute("beOrder",beOrder);
        return "be/be__billclearForm";

    }

    /**
     * 供水协议
     * @param model
     * @param ono
     * @return
     */
    @RequestMapping("/xieyi")
    public String yi(Model model,@RequestParam("ono") String ono){
        BeOrder beOrder = beOrderService.queryById(ono);
        System.out.println(beOrder);
        model.addAttribute("beOrder",beOrder);
        return "be/be__contractForm";

    }

    /**
     *施工竣工
     * @param model
     * @param ono
     * @return
     */
    @RequestMapping("/jungong")
    public String jun(Model model,@RequestParam("ono") String ono){
        BeOrder beOrder = beOrderService.queryById(ono);
        System.out.println(beOrder);
        model.addAttribute("beOrder",beOrder);
        return "be/be__workingForm";

    }
    /**
     *通水停水
     * @param model
     * @param ono
     * @return
     */
    @RequestMapping("/tingshui")
    public String ting(Model model,@RequestParam("ono") String ono){
        BeOrder beOrder = beOrderService.queryById(ono);
        System.out.println(beOrder);
        model.addAttribute("beOrder",beOrder);
        return "be/be__openForm";

    }
    /**
     *档案存档
     * @param model
     * @param ono
     * @return
     */
    @RequestMapping("/cundang")
    public String cun(Model model,@RequestParam("ono") String ono){
        BeOrder beOrder = beOrderService.queryById(ono);
        System.out.println(beOrder);
        model.addAttribute("beOrder",beOrder);
        return "be/be__saveForm";

    }
    /**
     *发送
     */
    @ResponseBody
    @RequestMapping("/go")
    public BeOrder dw(BeOrder beOrder,BeHistory beHistory){
        //查询对象得到当前步骤
        BeOrder ortype = this.beOrderService.queryById(beOrder.getOrderno());
        Integer ordertype = ortype.getOrdertype();
        Integer stepid = ortype.getStepid();
        Integer satrepid = orderNo.Setpid(stepid, ordertype);
        beOrder.setStepid(satrepid);
        beOrder.setLasteditdate(orderNo.CreateDate());
        BeOrder update = this.beOrderService.update(beOrder);
        beHistory.setOrderno(update.getOrderno());
        beHistory.setStepid(update.getStepid()-1);
        beHistory.setDatee(update.getLasteditdate());
        beHistory.setEmpid(update.getCreateemp());
        this.beHistoryService.insert(beHistory);
        return update;
    }
    /**
     * 撤回
     */
    @ResponseBody
    @RequestMapping("/abreak")
    public BeOrder abreak(BeOrder beOrder){
        Integer uid=beOrder.getAuditempid();
        beOrder = this.beOrderService.queryById(beOrder.getOrderno());
//        if (beOrder.getStepid() == 1) {
//            beOrder.setLasteditdate(orderNo.CreateDate());
//            beOrder = this.beOrderService.update(beOrder);
//        }else {
        Integer ordertype = beOrder.getOrdertype();
        Integer stepid = beOrder.getStepid();
        Integer satrepid = orderNo.Setpid_bk(stepid, ordertype);
        beOrder.setStepid(satrepid);
        beOrder.setAuditempid(uid);
        beOrder.setLasteditdate(orderNo.CreateDate());
        beOrder = this.beOrderService.update(beOrder);
        return beOrder;
    }
    /**
     *进入工单详情
     *
     */
    @RequestMapping("/be_orderlnfo")
    public String orderInfo(Model model, BeOrder beOrder, BeHistory beHistory){
        String orderno = beOrder.getOrderno();
        beHistory.setOrderno(orderno);
        BeOrder beOrderOne = this.beOrderService.queryById(orderno);
        List<Map<String, Object>> beHistories = this.beHistoryService.queryOrid(beHistory);
        Map<String,Object> map = new HashMap<>();
        if (beOrderOne.getStepid() == 2) {
            map.put("Datee"," ");
            map.put("StepName","初步审核");
            map.put("EmpName"," ");
            beHistories.add(map);
        }
        if (beOrderOne.getStepid() == 3) {
            map.put("Datee"," ");
            map.put("StepName","交施工费");
            map.put("EmpName"," ");
            beHistories.add(map);
        }
        if (beOrderOne.getStepid() == 4) {
            map.put("Datee"," ");
            map.put("StepName","水费清算");
            map.put("EmpName"," ");
            beHistories.add(map);
        }
        if (beOrderOne.getStepid() == 5) {
            map.put("Datee"," ");
            map.put("StepName","供水协议");
            map.put("EmpName"," ");
            beHistories.add(map);
        }
        if (beOrderOne.getStepid() == 6) {
            map.put("Datee"," ");
            map.put("StepName","施工竣工");
            map.put("EmpName"," ");
            beHistories.add(map);
        }
        if (beOrderOne.getStepid() == 7) {
            map.put("Datee"," ");
            map.put("StepName","通水停水");
            map.put("EmpName"," ");
            beHistories.add(map);
        }
        if (beOrderOne.getStepid() == 8) {
            map.put("Datee"," ");
            map.put("StepName","档案存档");
            map.put("EmpName"," ");
            beHistories.add(map);
        }
        model.addAttribute("ordernoOne",beOrderOne);
        model.addAttribute("beHistories",beHistories);
        return "be/be_orderInfo";
    }
    /**
     * 业扩工程进度
     */
    @RequestMapping("/be_reportProgress")
    public String countOrder(Model model,BeOrder beOrder) {
        System.out.println("sss");
        Map<String, Object> map = new HashMap<>();
        Integer st = 0;
        for (int i = 1; i <= 7; i++) {
            System.out.println("uuuu");
            for (int j = -1; j <= 8; j++) {
                if ((i == 1 && j == 4) || ((i == 3 || i == 4) && (j > 2 && j < 7)) || (i == 5 && (j > 3 && j < 6)) || (i == 6 && (j > 2 && j != 5 && j == 7)) || (i == 7 && (j == 3 || j == 5 || j == 6 ))) {
                    continue;
                } else {
                    beOrder.setOrdertype(i);
                    beOrder.setStepid(j);
                    st = beOrderService.couOrder(beOrder);
//                    System.out.println(st+"1231234");
                    if (j == -1) {
                        map.put("t" + i + "s9" , st);
                    }else {
                        map.put("t" + i + "s" + j, st);
                    }

                }
                System.out.println(map+"-000000000011-");
                model.addAttribute("ts", map);
            }
        }

        return "be/be_reportProgress";
    }

}